from PySide2.QtWidgets import QLabel
from PySide2.QtGui import QPixmap

from custom.LabelButton import LabelButton

from tool import util, storage
from custom.Runthread import LoadImage

class ImageWidget(LabelButton):

    def __init__(self):
        super(ImageWidget, self).__init__()
        self.thread = LoadImage()
        self.thread.finishsignal.connect(self.finishImage)

    def loadImage(self, id, img):
        self.thread.setImg(id, img)
        self.thread.start()

    def finishImage(self, id, pixmap):
        self.setPixmap(pixmap)
        (width, height) = util.getImageSize(pixmap.width(), pixmap.height())
        self.setFixedSize(width, height)

    def clearImage(self):
        self.setPixmap(QPixmap(""))
